//
//  DataViewController.m
//  Frame
//
//  Created by 这是工作本 on 16/2/18.
//  Copyright © 2016年 这是工作本. All rights reserved.
//

#import "DataViewController.h"

@interface DataViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property (nonatomic, retain) UIImageView *photo;

@property (nonatomic, retain) UIAlertController *alertC;

@property (nonatomic, retain) UIButton *nickname;

@property (nonatomic, retain) UIButton *sex;

@property (nonatomic, retain) UIButton *city;

@property (nonatomic, retain) UIButton *mobilePhone;

@property (nonatomic, retain) UIButton *QQ;

@property (nonatomic, retain) UIButton *next;

@end

@implementation DataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:240 / 255.0 green:240 / 255.0 blue:240 / 255.0 alpha:1.0];
    self.navigationItem.title = @"完善资料";
    //隐藏自动返回
    self.navigationItem.hidesBackButton = YES;
    //返回按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"but_an.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonAction:)];
    
    //用户头像
    self.photo = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2 - 35 * ScreenWidth, 35 * ScreenHeigth, 70 * ScreenWidth, 70 * ScreenHeigth)];
    self.photo.layer.masksToBounds = YES;
    self.photo.layer.cornerRadius = 35 * ScreenWidth;
    
    //添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoChange)];
    self.photo.image = [UIImage imageNamed:@"椭圆-18@2x.png"];
    
    //图片交互
    self.photo.userInteractionEnabled = YES;
    [self.photo addGestureRecognizer:tap];
    [self.view addSubview:self.photo];
    
    
    //昵称
    
    self.nickname = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nickname.frame = CGRectMake(0, self.photo.frame.origin.y + self.photo.frame.size.height + 35 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width, 50 * ScreenHeigth);
    //设置字体大小
    self.nickname.titleLabel.font = [UIFont systemFontOfSize:15.0 * ScreenWidth];
    [self.nickname setTitleColor:[UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    self.nickname.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    [self.nickname setTitle:@"昵称" forState:UIControlStateNormal];
    //设置字体靠左
    self.nickname.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //设置字体位置
    self.nickname.contentEdgeInsets = UIEdgeInsetsMake(0,15 * ScreenWidth, 0, 0);
    
    [self.nickname addTarget:self action:@selector(orderAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.nickname];
    
    //箭头
    UIImageView *imageC = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 20 * ScreenWidth, self.nickname.frame.origin.y + 19 * ScreenHeigth, 8 * ScreenWidth, 12 * ScreenHeigth)];
    imageC.image = [UIImage imageNamed:@"形状-1-拷贝-3@2x.png"];
    [self.view addSubview:imageC];
    
    
  

    
    
    //性别
    
    self.sex = [UIButton buttonWithType:UIButtonTypeCustom];
    self.sex.frame = CGRectMake(0, self.nickname.frame.origin.y + self.nickname.frame.size.height + 1 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width, 50 * ScreenHeigth);
    //设置字体大小
    self.sex.titleLabel.font = [UIFont systemFontOfSize:15.0 * ScreenWidth];
    [self.sex setTitleColor:[UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    self.sex.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    [self.sex setTitle:@"性别" forState:UIControlStateNormal];
    //设置字体靠左
    self.sex.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //设置字体位置
    self.sex.contentEdgeInsets = UIEdgeInsetsMake(0,15 * ScreenWidth, 0, 0);
    
    [self.sex addTarget:self action:@selector(orderAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.sex];
    
    //箭头
    UIImageView *imageS = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 20 * ScreenWidth, self.sex.frame.origin.y + 19 * ScreenHeigth, 8 * ScreenWidth, 12 * ScreenHeigth)];
    imageS.image = [UIImage imageNamed:@"形状-1-拷贝-3@2x.png"];
    [self.view addSubview:imageS];

    
    
    //城市
    
    self.city = [UIButton buttonWithType:UIButtonTypeCustom];
    self.city.frame = CGRectMake(0, self.sex.frame.origin.y + self.sex.frame.size.height + 20 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width, 50 * ScreenHeigth);
    //设置字体大小
    self.city.titleLabel.font = [UIFont systemFontOfSize:15.0 * ScreenWidth];
    [self.city setTitleColor:[UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    self.city.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    [self.city setTitle:@"城市" forState:UIControlStateNormal];
    //设置字体靠左
    self.city.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //设置字体位置
    self.city.contentEdgeInsets = UIEdgeInsetsMake(0,15 * ScreenWidth, 0, 0);
    
    [self.city addTarget:self action:@selector(orderAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.city];
    
    //箭头
    UIImageView *imageY = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 20 * ScreenWidth, self.city.frame.origin.y + 19 * ScreenHeigth, 8 * ScreenWidth, 12 * ScreenHeigth)];
    imageY.image = [UIImage imageNamed:@"形状-1-拷贝-3@2x.png"];
    [self.view addSubview:imageY];

    
    
    
    //绑定手机号
    
    self.mobilePhone = [UIButton buttonWithType:UIButtonTypeCustom];
    self.mobilePhone.frame = CGRectMake(0, self.city.frame.origin.y + self.city.frame.size.height + 1 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width, 50 * ScreenHeigth);
    //设置字体大小
    self.mobilePhone.titleLabel.font = [UIFont systemFontOfSize:15.0 * ScreenWidth];
    [self.mobilePhone setTitleColor:[UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    self.mobilePhone.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    [self.mobilePhone setTitle:@"绑定手机号" forState:UIControlStateNormal];
    //设置字体靠左
    self.mobilePhone.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //设置字体位置
    self.mobilePhone.contentEdgeInsets = UIEdgeInsetsMake(0,15 * ScreenWidth, 0, 0);
    
    [self.mobilePhone addTarget:self action:@selector(orderAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.mobilePhone];
    
    //箭头
    UIImageView *imageM = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 20 * ScreenWidth, self.mobilePhone.frame.origin.y + 19 * ScreenHeigth, 8 * ScreenWidth, 12 * ScreenHeigth)];
    imageM.image = [UIImage imageNamed:@"形状-1-拷贝-3@2x.png"];
    [self.view addSubview:imageM];

    
    
    //绑定QQ
    
    self.QQ = [UIButton buttonWithType:UIButtonTypeCustom];
    self.QQ.frame = CGRectMake(0, self.mobilePhone.frame.origin.y + self.mobilePhone.frame.size.height + 1 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width, 50 * ScreenHeigth);
    //设置字体大小
    self.QQ.titleLabel.font = [UIFont systemFontOfSize:15.0 * ScreenWidth];
    [self.QQ setTitleColor:[UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    self.QQ.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    [self.QQ setTitle:@"绑定QQ" forState:UIControlStateNormal];
    //设置字体靠左
    self.QQ.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //设置字体位置
    self.QQ.contentEdgeInsets = UIEdgeInsetsMake(0,15 * ScreenWidth, 0, 0);
    
    [self.QQ addTarget:self action:@selector(orderAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.QQ];
    
    //箭头
    UIImageView *imageQ = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 20 * ScreenWidth, self.QQ.frame.origin.y + 19 * ScreenHeigth, 8 * ScreenWidth, 12 * ScreenHeigth)];
    imageQ.image = [UIImage imageNamed:@"形状-1-拷贝-3@2x.png"];
    [self.view addSubview:imageQ];

    
    
    //提交
    
    self.next = [UIButton buttonWithType:UIButtonTypeCustom];
    self.next.frame = CGRectMake(10 * ScreenWidth, self.QQ.frame.origin.y + self.QQ.frame.size.height + 30 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width - 20 * ScreenWidth, 50 * ScreenHeigth);
    //圆角
    self.next.layer.cornerRadius = 5 * ScreenWidth;
    self.next.layer.masksToBounds = YES;
    
    //设置字体大小
    self.next.titleLabel.font = [UIFont systemFontOfSize:15.0 * ScreenWidth];
    [self.next setTitleColor:[UIColor colorWithRed:29 / 255.0 green:127 / 255.0 blue:140 / 255.0 alpha:1.0] forState:UIControlStateNormal];
    self.next.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    [self.next setTitle:@"提交" forState:UIControlStateNormal];
    //设置字体居中
    self.next.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    
    [self.next addTarget:self action:@selector(orderAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.next];

    
    
    //弹出选择
    //拍照
    self.alertC = [[UIAlertController alloc] init];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        
        
    }];
    
    //拍照
    UIAlertAction *photo = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            
            UIImagePickerController *pick = [[UIImagePickerController alloc] init];
            pick.delegate = self;
            pick.allowsEditing = YES;
            pick.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:pick animated:YES completion:^{
                
                
            }];
            
        } else {
            
            NSLog(@"没有相机");
        }
        
    }];
    
    //从相册选取
    
    UIAlertAction *photograph = [UIAlertAction actionWithTitle:@"从相册中选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        [self presentViewController:imagePicker animated:YES completion:nil];
        
    }];
    
    [self.alertC addAction:action];
    [self.alertC addAction:photo];
    [self.alertC addAction:photograph];
    


    
}

- (void)orderAction:(UIButton *)sender
{
    
}

- (void)leftBarButtonAction:(UIBarButtonItem *)sender
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)photoChange
{
    //模态推出
    [self presentViewController:self.alertC animated:YES completion:^{
        
    }];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    UIImage *image = info[@"UIImagePickerControllerOriginalImage"];
    [self.photo setImage:image];
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
